import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { AgentService } from '@core/routes-services/agent.service';
import { MyModalHelper } from '@core/my-modal.helper';
import { NzMessageService } from 'ng-zorro-antd';

@Component({
  selector: 'agent-child',
  templateUrl: './agent-child.component.html',
  styles: []
})
export class AgentChildComponent implements OnInit,OnChanges {

  @Input() parentId = 0;
  @Input()levelOptions: any [] = [];

  isLoading = false;
  keyword: any;
  levelId:any;

  page: any = { number: 1, size: 10, totalElements: 0, content: [] };

  constructor(private message: NzMessageService,
              private agentService:AgentService,
              private modalHelper: MyModalHelper) {
  }


  ngOnInit() {
    this.initPage();
  }

  ngOnChanges(changes: SimpleChanges): void {
    // console.log(changes)
    // console.log("changes-----AgentChildComponent------==-"+this.parentId)
  }

  initPage() {
    this.isLoading = true;
    // console.log("this.parentId-----AgentChildComponent------==-"+this.parentId)
    this.agentService.pagination(this.page, this.keyword, this.levelId, this.parentId,null).then((res) => {
      if (res.status.toString().startsWith("20")) {
        this.page = res.data;
        ++this.page.number;
      } else {
        this.message.warning(res.message);
      }
      this.isLoading = false;
    }, error => {
      this.message.error(error.message ? error.message : error.error)
      this.isLoading = false;
    });
  }

  /**
   * 搜索重置分页数据
   */
  search() {
    this.page = { number: 0, size: 10, totalElements: 0, content: [] };
    this.initPage();
  }

  changePageNo(pageNo) {
    this.page = { number: pageNo, size: 10, totalElements: 0, content: [] };
    this.initPage();
  }


}
